package com.onpositive.rest.model;

import java.util.ArrayList;
import java.util.LinkedHashMap;

public class Method {
	
	private String uri;
	
	private String description;
	
	private HttpType httpType;
	
	private Body body = new Body();
	
	private LinkedHashMap<Integer,Response> responses = new LinkedHashMap<Integer, Response>();
	
	private LinkedHashMap<String,Param> formParams = new LinkedHashMap<String, Param>();
	
	private LinkedHashMap<String,Param> queryParams = new LinkedHashMap<String, Param>();
	
	private LinkedHashMap<String,Param> params = new LinkedHashMap<String, Param>();
	
	private ArrayList<String> sampleRequests = new ArrayList<String>();
	
	private LinkedHashMap<String, LinkedHashMap<String,Param>> otherParams = new LinkedHashMap<String, LinkedHashMap<String,Param>>();
	
	private ArrayList<String> examples = new ArrayList<String>();

	public ArrayList<String> getExamples() {
		return examples;
	}

	public void addExample(String example) {
		this.examples.add(example);
	}
	
	public String getSignature(){
		return httpType.name()+ " " + uri;
	}

	public String getDescription() {
		return description;
	}

	public HttpType getHttpType() {
		return httpType;
	}

	public void setHttpType(HttpType httpType) {
		this.httpType = httpType;
	}

	public Body getBody() {
		return body;
	}

	public void setBody(Body body) {
		this.body = body;
	}

	public LinkedHashMap<Integer, Response> getResponses() {
		return responses;
	}

	public void setResponses(LinkedHashMap<Integer, Response> responses) {
		this.responses = responses;
	}

	public LinkedHashMap<String, Param> getFormParams() {
		return formParams;
	}

	public void setFormParams(LinkedHashMap<String, Param> formParams) {
		this.formParams = formParams;
	}

	public LinkedHashMap<String, Param> getQueryParams() {
		return queryParams;
	}

	public void setQueryParams(LinkedHashMap<String, Param> queryParams) {
		this.queryParams = queryParams;
	}

	public LinkedHashMap<String, Param> getParams() {
		return params;
	}

	public void setParams(LinkedHashMap<String, Param> params) {
		this.params = params;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public ArrayList<String> getSampleRequests() {
		return sampleRequests;
	}

	public void setSampleRequests(ArrayList<String> requests) {
		this.sampleRequests = requests;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((body == null) ? 0 : body.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result
				+ ((formParams == null) ? 0 : formParams.hashCode());
		result = prime * result
				+ ((httpType == null) ? 0 : httpType.hashCode());
		result = prime * result + ((params == null) ? 0 : params.hashCode());
		result = prime * result
				+ ((queryParams == null) ? 0 : queryParams.hashCode());
		result = prime * result
				+ ((responses == null) ? 0 : responses.hashCode());
		result = prime * result
				+ ((sampleRequests == null) ? 0 : sampleRequests.hashCode());
		result = prime * result + ((uri == null) ? 0 : uri.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Method other = (Method) obj;
		if (body == null) {
			if (other.body != null)
				return false;
		} else if (!body.equals(other.body))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (formParams == null) {
			if (other.formParams != null)
				return false;
		} else if (!formParams.equals(other.formParams))
			return false;
		if (httpType != other.httpType)
			return false;
		if (params == null) {
			if (other.params != null)
				return false;
		} else if (!params.equals(other.params))
			return false;
		if (queryParams == null) {
			if (other.queryParams != null)
				return false;
		} else if (!queryParams.equals(other.queryParams))
			return false;
		if (responses == null) {
			if (other.responses != null)
				return false;
		} else if (!responses.equals(other.responses))
			return false;
		if (sampleRequests == null) {
			if (other.sampleRequests != null)
				return false;
		} else if (!sampleRequests.equals(other.sampleRequests))
			return false;
		if (uri == null) {
			if (other.uri != null)
				return false;
		} else if (!uri.equals(other.uri))
			return false;
		return true;
	}

	public LinkedHashMap<String, LinkedHashMap<String, Param>> getOtherParams() {
		return otherParams;
	}

	public void setOtherParams(
			LinkedHashMap<String, LinkedHashMap<String, Param>> otherParams) {
		this.otherParams = otherParams;
	}
}
